package com.baseframe.sys.service.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baseframe.sys.entity.AppUserRelation;
import com.baseframe.sys.service.IAppUserRelationService;
import com.baseframe.sys.service.dao.AppUserRelationRepository;


@Transactional(rollbackFor = Exception.class)
@Service
public class AppUserRelationServiceImpl implements IAppUserRelationService {
    @Autowired
    private AppUserRelationRepository appUserRelationRepository;
    @PersistenceContext
    private EntityManager em;


	@Override
	public int deleteByPrimaryKey(int id) {
		return appUserRelationRepository.deleteById(id);
	}

	@Override
	public AppUserRelation save(AppUserRelation record) {
		return appUserRelationRepository.save(record);
	}

	@Override
	public AppUserRelation findOne(int id) {
		return appUserRelationRepository.findOne(id);
	}

	@Override
	public List<AppUserRelation> getByAppidAndAllowtype(int appid,String allowtype) {
		return appUserRelationRepository.getByAppidAndAllowtype(appid,allowtype);
	}

	@Override
	public int deleteByAppidAndAllowtype(int appid, String allowtype) {
		return appUserRelationRepository.deleteByAppidAndAllowtype(appid, allowtype);
	}
	
	@Override
	public List<Integer> getAllowByType(int appid,String allowtype) {
		String hql="select allowto from AppUserRelation where appid='"+appid+"' and allowtype='"+allowtype+"'";
		return em.createQuery(hql).getResultList();
	}


}
